$(document).ready(function(){
	$(".alert").alert();
	$("#btnlogin").popover({placement:'bottom'});
	$("#color-chooser").popover({placement:'bottom'}); 	
	$(".popup_alert").fadeIn(400).delay(4000).fadeOut(400);//fermeture auto des popup
	$(".tooltip_top").tooltip();
	
	
	$("#add_product").click(function(){
		var id = $("#select_products option:selected").val();
		var price = $("#select_products option:selected").attr("data");
		var label = $("#select_products option:selected").text();
		
		$("#list_choosen_product").append("<div>" +
					"<input type='hidden' value='"+id+"' name='product[]' />"+
					"<span class=''>"+label+"</span> : <input type='number' required='required' min='1' value='1' class='qte' name='qte[]' data='"+price+"' />" +
					"<i class='icon icon-remove vertical_center' id='delete_product'></i>" +
				"</div>");
			
		$("#list_choosen_product").children().last().find("#delete_product").click(function(){
			$(this).parent().html("");
			updatePrice();	
		});
		
		$("#list_choosen_product").children().last().find(".qte").change(function(){updatePrice();});
		//alert($("#list_choosen_product div").last().find(".qte").val());
		updatePrice();		
	});
	
	
	//
});


function updatePrice(){
	var sum = 0;
	$(".qte").each(function(){
		sum += ($(this).attr("data") * $(this).val()); 
	});
	
	$("#total_purchase").html(sum.toFixed(2));
}

